﻿using JavaDevToys.Rcl;
using JavaDevToys.Rcl.Context;
using JavaDevToys.Rcl.Service;
using JavaDevToys.Service.Impl;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
#if WINDOWS
using JavaDevToys.Platforms.Windows.Service.Impl;
#endif

namespace JavaDevToys
{
    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
              .UseMauiApp<App>()
              .ConfigureFonts(fonts =>
              {
                  fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
              });
            builder.Services.AddDbContext<HisDbContext>(context => context.UseSqlServer("Server=10.0.0.220;Database=HISDB;uid=HIS_DICT;pwd=HIS_DICT@123;TrustServerCertificate=true"));
            builder.Services.AddMauiBlazorWebView();
            builder.Services.AddMasaBlazor();

#if DEBUG
    		builder.Services.AddBlazorWebViewDeveloperTools();
    		builder.Logging.AddDebug();
#endif

            builder.Services.AddScoped<IJavaFileService, JavaFileService>();
            builder.Services.AddScoped<IJavaProjectService, Rcl.Service.Impl.JavaProjectService>();
            builder.Services.AddScoped<IApiInfoParser, Rcl.Service.Impl.ApiInfoParser>();
            builder.Services.AddScoped<IJavaCodeGenerator, Rcl.Service.Impl.JavaCodeGenerator>();
            builder.Services.AddScoped<IParameterInfoParser, Rcl.Service.Impl.ParameterInfoParser>();
            builder.Services.AddScoped<IJavaServiceParser, Rcl.Service.Impl.JavaServiceParser>();
            builder.Services.AddScoped<IJavaMapperParser, Rcl.Service.Impl.JavaMapperParser>();
            builder.Services.AddScoped<IJavaEnumParser, Rcl.Service.Impl.JavaEnumParser>();
            builder.Services.AddScoped<ICSharpCodeGenerator, Rcl.Service.Impl.CSharpCodeGenerator>();
            builder.Services.AddScoped<IExInterfaceCodeService, Rcl.Service.Impl.ExInterfaceCodeService>();
            builder.Services.AddEntityAutoMapper();
#if WINDOWS
            builder.Services.AddTransient<IDirectoryPicker, DirectoryPicker>();
            builder.Services.AddScoped<IClipboardService, ClipboardService>();
            builder.Services.AddScoped<ISettingService, SettingService>();
#endif
            return builder.Build();
        }
    }
}
